package com.example.test;

import controller.Controlador;
import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class RegistroActivity extends ActionBarActivity {
	
	EditText usernameET;
	EditText passwordET;
	EditText passwordreET;
	
	EditText nombresET;
	EditText apellidosET;
	
	Button registroBtn;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_registro);
		
		usernameET = (EditText) findViewById(R.id.usernameRegistroEditText);
		passwordET = (EditText) findViewById(R.id.passwordRegistroEditText);
		passwordreET = (EditText) findViewById(R.id.passwordRERegistroEditText);
		
		nombresET = (EditText) findViewById(R.id.nombresRegistroEditText);
		apellidosET = (EditText) findViewById(R.id.apellidosRegistroEditText);
		
		
		
		registroBtn = (Button) findViewById(R.id.registrateBtnRegistro);
		
		registroBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				controller.Controlador.registro(usernameET.getText().toString(),
						passwordET.getText().toString(),
						nombresET.getText().toString(),
						apellidosET.getText().toString());
				AlertDialog.Builder builder =
 new AlertDialog.Builder(
						RegistroActivity.this);

				builder.setMessage(
						usernameET.getText().toString() + "\n"
								+ passwordET.getText().toString()
								+ "\n\nGuarda estos datos en un lugar seguro!")
						.setTitle("Registro completado!")
						.setPositiveButton("Entendido",
								new DialogInterface.OnClickListener() {
									public void onClick(DialogInterface dialog,
											int id) {
										Intent main = new Intent(
												RegistroActivity.this,
												MainActivity.class);
										finish();
										startActivity(main);
										dialog.cancel();
									}
								});

				AlertDialog dialog = builder.create();
		        dialog.show();
			}
		});
		
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.registro, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
